/* eslint-disable no-var */

function changePhone(str) {
  str += "";
  var strArr = str.split("");
  for (var i = 4; i < 8; i++) {
    strArr[i] = "*";
  }
  return strArr.join("");
}

function phoneStatus(phone, authorizeStatus, showStatus) {
  if (!phone) return { status: 1 }; // 如果手机号码不存在不显示
  if (authorizeStatus == 1) return { phone: phone, status: 1 }; // 如果手机号已经授权显示手机号码 不需要手机号授权
  if (showStatus != 1) {
    // 对所有用户显示
    return { phone: phone, status: 1 };
  } else {
    // 只对授权的用户显示 需要显示授权
    return { phone: changePhone(phone), status: 0 };
  }
}

function isScholl(id, idArr) {
  if (!idArr) return false;
  return idArr.indexOf(id) > -1;
}
function longStringSplit(str, length) {
  return str && str.length > length ? str.slice(0, length) + "..." : str;
}

function changeNum(num) {
  if (num < 1000) {
    return num;
  } else if (num >= 1000 && num < 10000) {
    return Math.floor(num / 1000) + "." + Math.floor((num % 1000) / 100) + "K";
  } else {
    return (
      Math.floor(num / 10000) + "." + Math.floor((num % 10000) / 1000) + "W"
    );
  }
}

// eslint-disable-next-line import/no-commonjs
module.exports = {
  isScholl: isScholl,
  phoneStatus: phoneStatus,
  longStringSplit,
  changeNum,
};
